
$.wait = function(time) {
  return $.Deferred(function(dfd) {
    setTimeout(dfd.resolve, time);
  });
}

var levels=[],lev_label=[];

var our_month=['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'];

function set_modal()
{
     var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#myModalnew_edit").height();
    var popupWidth = $("#myModalnew_edit").width();
    
    
    var top_n=windowHeight/2-popupHeight/2;
    var left_n=windowWidth/2-popupWidth/2;
        
        if (windowWidth >900) {
           $('#myModalnew_edit').css('width','540px'); 
           left_n=windowWidth/2-540/2;
           
        }
        
        if (windowWidth <601) {
            left_n=10;
            }
        left_n=10;
         $('#myModalnew_edit').css('left',left_n);
         
         //$('.cloud_user_name').val(windowWidth+'+'+left_n+'+'+popupWidth);
}

function getDataInfoStreams(c_id) {
	
    ajaxLoadingOn();
    
    $.post('infostreams/tree', {id:c_id},
      function(data){
        
        ///////////////////////////////////////////////////////////// 942
        //alert("Data Loaded: " + data.message);
        //console.log(data);        
          
        
                
        bDatan = data.message;
        
        var b_status = data.status;
        
        if (b_status!='error') {
            
        var w = $('.testmain_clouds').width();
    h = $('.testmain_clouds').height();
    
    var z = 20,
    x = w / z,
    y = h / z;
    
    

var radius = d3.scale.sqrt().range([0, 6]);

$('.testmain_clouds svg').remove();

var svg = d3.select(".testmain_clouds").append("svg")
    .attr("width", w)
    .attr("height", h);
    
        var nodes = [],links = [];
        
        var with_link=0;
        var node_id=0;
        var kk=0;
        var kk1=0;
        var kk2=0;
        var node_link=[];
        var node_link_p=[];
        var node_link_w=[];
             
        for(var i in bDatan){
            var c_s=0;
            if (bDatan[i]['parent']==0) {c_s=20;} else {c_s=15;} 
            
            var created_by='';
            
             if (bDatan[i]['created_by']!=null) {
                created_by=bDatan[i]['created_by']['display_name'];
             }
            nodes.push({
                "atom": bDatan[i]['title'],
                "size": c_s,
                "id_node":bDatan[i]['id'],
                "level_node":bDatan[i]['level'],
                "parent_node":bDatan[i]['parent'],
                "last_level":bDatan[i]['_is_last_level'],
                "n_id":with_link,
                "version":bDatan[i]['version'],
                "performance":bDatan[i]['performance'],
                "density":bDatan[i]['density'],
                "energy":bDatan[i]['energy'],
                "emotional_coloring":bDatan[i]['emotional_coloring'],
                "description":bDatan[i]['description'],
                "doc1":bDatan[i]['doc1'],
                "doc2":bDatan[i]['doc2'],
                "doc3":bDatan[i]['doc3'],
                "doc4":bDatan[i]['doc4'],
                "doc5":bDatan[i]['doc5'],
                "doc6":bDatan[i]['doc6'],
                "doc7":bDatan[i]['doc7'],
                "doc8":bDatan[i]['doc8'],
                "doc9":bDatan[i]['doc9'],
                "doc10":bDatan[i]['doc10'],
                "doc11":bDatan[i]['doc11'],
                "doc12":bDatan[i]['doc12'],
                "doc13":bDatan[i]['doc13'],
                "doc14":bDatan[i]['doc14'],
                "doc15":bDatan[i]['doc15'],
                "x_pos":bDatan[i]['x_pos'],
                "y_pos":bDatan[i]['y_pos'],
                "date_completion":bDatan[i]['date_completion'],
                "spent_time":bDatan[i]['spent_time'],
                "created_by":created_by,
                "_is_creator":bDatan[i]['_is_creator']
                });
        
        node_id++;
        node_link[i]=bDatan[i]['id'];
        node_link_p[i]=bDatan[i]['parent'];
        node_link_w[i]=node_id-1;
        
        var data_child=bDatan[i]['_childs'];

            for(var k in data_child){
                
                var c_s1=c_s-6;            
                var created_by='';
                if (data_child[k]['created_by']!=null) {
                created_by=data_child[k]['created_by']['display_name'];
             }
             
                nodes.push({
                "atom": data_child[k]['title'],
                "size": c_s1,
                "id_node":data_child[k]['id'],
                "level_node":data_child[k]['level'],
                "parent_node":data_child[k]['parent'],
                "last_level":data_child[k]['_is_last_level'],
                "n_id":with_link,
                "version":data_child[k]['version'],
                "performance":data_child[k]['performance'],
                "density":data_child[k]['density'],
                "energy":data_child[k]['energy'],
                "emotional_coloring":data_child[k]['emotional_coloring'],
                "description":data_child[k]['description'],
                "doc1":data_child[k]['doc1'],
                "doc2":data_child[k]['doc2'],
                "doc3":data_child[k]['doc3'],
                "doc4":data_child[k]['doc4'],
                "doc5":data_child[k]['doc5'],
                "doc6":data_child[k]['doc6'],
                "doc7":data_child[k]['doc7'],
                "doc8":data_child[k]['doc8'],
                "doc9":data_child[k]['doc9'],
                "doc10":data_child[k]['doc10'],
                "doc11":data_child[k]['doc11'],
                "doc12":data_child[k]['doc12'],
                "doc13":data_child[k]['doc13'],
                "doc14":data_child[k]['doc14'],
                "doc15":data_child[k]['doc15'],
                "x_pos":data_child[k]['x_pos'],
                "y_pos":data_child[k]['y_pos'],
                "date_completion":data_child[k]['date_completion'],
                "spent_time":data_child[k]['spent_time'],
                "created_by":created_by,
                "_is_creator":data_child[k]['_is_creator']     
                    });
                node_id++;
                node_link[k]=data_child[k]['id'];
                node_link_p[k]=data_child[k]['parent'];
                node_link_w[k]=node_id-1;
                
                //---------------------------------------------------------------------------
            var data_child1=data_child[k]['_childs']; 
                for(var k1 in data_child1){
                    var c_s2=c_s1-2;
                    var created_by='';
                 if (data_child1[k1]['created_by']!=null) {
                created_by=data_child1[k1]['created_by']['display_name'];
             }
             
                 nodes.push({
                "atom": data_child1[k1]['title'],
                "size": c_s2,
                "id_node":data_child1[k1]['id'],
                "level_node":data_child1[k1]['level'],
                "parent_node":data_child1[k1]['parent'],
                "last_level":data_child1[k1]['_is_last_level'],
                "n_id":with_link,
                "version":data_child1[k1]['version'],
                "performance":data_child1[k1]['performance'],
                "density":data_child1[k1]['density'],
                "energy":data_child1[k1]['energy'],
                "emotional_coloring":data_child1[k1]['emotional_coloring'],
                "description":data_child1[k1]['description'],
                "doc1":data_child1[k1]['doc1'],
                "doc2":data_child1[k1]['doc2'],
                "doc3":data_child1[k1]['doc3'],
                "doc4":data_child1[k1]['doc4'],
                "doc5":data_child1[k1]['doc5'],
                "doc6":data_child1[k1]['doc6'],
                "doc7":data_child1[k1]['doc7'],
                "doc8":data_child1[k1]['doc8'],
                "doc9":data_child1[k1]['doc9'],
                "doc10":data_child1[k1]['doc10'],
                "doc11":data_child1[k1]['doc11'],
                "doc12":data_child1[k1]['doc12'],
                "doc13":data_child1[k1]['doc13'],
                "doc14":data_child1[k1]['doc14'],
                "doc15":data_child1[k1]['doc15'],
                "x_pos":data_child1[k1]['x_pos'],
                "y_pos":data_child1[k1]['y_pos'],
                "date_completion":data_child1[k1]['date_completion'],
                "spent_time":data_child1[k1]['spent_time'],
                "created_by":created_by,
                "_is_creator":data_child1[k1]['_is_creator']     
                 });   
                    
                    node_id++;
                node_link[k1]=data_child1[k1]['id'];
                node_link_p[k1]=data_child1[k1]['parent'];
                node_link_w[k1]=node_id-1;
                    
                    var data_child2=data_child1[k1]['_childs'];
                    for(var k2 in data_child2){
                        var c_s3=c_s2-2;
                        var created_by='';
                        if (data_child2[k2]['created_by']!=null) {
                created_by=data_child2[k2]['created_by']['display_name'];
             }
             
                        nodes.push({
                "atom": data_child2[k2]['title'],
                "size": c_s3,
                "id_node":data_child2[k2]['id'],
                "level_node":data_child2[k2]['level'],
                "parent_node":data_child2[k2]['parent'],
                "last_level":data_child2[k2]['_is_last_level'],
                "n_id":with_link,
                "version":data_child2[k2]['version'],
                "performance":data_child2[k2]['performance'],
                "density":data_child2[k2]['density'],
                "energy":data_child2[k2]['energy'],
                "emotional_coloring":data_child2[k2]['emotional_coloring'],
                "description":data_child2[k2]['description'],
                "doc1":data_child2[k2]['doc1'],
                "doc2":data_child2[k2]['doc2'],
                "doc3":data_child2[k2]['doc3'],
                "doc4":data_child2[k2]['doc4'],
                "doc5":data_child2[k2]['doc5'],
                "doc6":data_child2[k2]['doc6'],
                "doc7":data_child2[k2]['doc7'],
                "doc8":data_child2[k2]['doc8'],
                "doc9":data_child2[k2]['doc9'],
                "doc10":data_child2[k2]['doc10'],
                "doc11":data_child2[k2]['doc11'],
                "doc12":data_child2[k2]['doc12'],
                "doc13":data_child2[k2]['doc13'],
                "doc14":data_child2[k2]['doc14'],
                "doc15":data_child2[k2]['doc15'],
                "x_pos":data_child2[k2]['x_pos'],
                "y_pos":data_child2[k2]['y_pos'],
                "date_completion":data_child2[k2]['date_completion'],
                "spent_time":data_child2[k2]['spent_time'],
                "created_by":created_by,
                "_is_creator":data_child1[k1]['_is_creator']     
                            });   
                    
                        node_id++;
                        node_link[k2]=data_child2[k2]['id'];
                        node_link_p[k2]=data_child2[k2]['parent'];
                        node_link_w[k2]=node_id-1;
                        
                        //--------------------------
                         var data_child3=data_child2[k2]['_childs'];
                         for(var k3 in data_child3){
                            var c_s4=c_s3-2;
                            var created_by='';
                            if (data_child3[k3]['created_by']!=null) {
                created_by=data_child3[k3]['created_by']['display_name'];
             }
             
                        nodes.push({
                "atom": data_child3[k3]['title'],
                "size": c_s4,
                "id_node":data_child3[k3]['id'],
                "level_node":data_child3[k3]['level'],
                "parent_node":data_child3[k3]['parent'],
                "last_level":data_child3[k3]['_is_last_level'],
                "n_id":with_link,
                "version":data_child3[k3]['version'],
                "performance":data_child3[k3]['performance'],
                "density":data_child3[k3]['density'],
                "energy":data_child3[k3]['energy'],
                "emotional_coloring":data_child3[k3]['emotional_coloring'],
                "description":data_child3[k3]['description'],
                "doc1":data_child3[k3]['doc1'],
                "doc2":data_child3[k3]['doc2'],
                "doc3":data_child3[k3]['doc3'],
                "doc4":data_child3[k3]['doc4'],
                "doc5":data_child3[k3]['doc5'],
                "doc6":data_child3[k3]['doc6'],
                "doc7":data_child3[k3]['doc7'],
                "doc8":data_child3[k3]['doc8'],
                "doc9":data_child3[k3]['doc9'],
                "doc10":data_child3[k3]['doc10'],
                "doc11":data_child3[k3]['doc11'],
                "doc12":data_child3[k3]['doc12'],
                "doc13":data_child3[k3]['doc13'],
                "doc14":data_child3[k3]['doc14'],
                "doc15":data_child3[k3]['doc15'],
                "x_pos":data_child3[k3]['x_pos'],
                "y_pos":data_child3[k3]['y_pos'],
                "date_completion":data_child3[k3]['date_completion'],
                "spent_time":data_child3[k3]['spent_time'],
                "created_by":created_by,
                "_is_creator":data_child3[k3]['_is_creator']     
                            });   
                    
                        node_id++;
                        node_link[k3]=data_child3[k3]['id'];
                        node_link_p[k3]=data_child3[k3]['parent'];
                        node_link_w[k3]=node_id-1;
                        
                            //-------------------
                            var data_child4=data_child3[k3]['_childs'];
                            for(var k4 in data_child4){
                              var c_s5=c_s4-1;
                              var created_by='';
                              if (data_child4[k4]['created_by']!=null) {
                created_by=data_child4[k4]['created_by']['display_name'];
             }
             
                        nodes.push({
                "atom": data_child4[k4]['title'],
                "size": c_s5,
                "id_node":data_child4[k4]['id'],
                "level_node":data_child4[k4]['level'],
                "parent_node":data_child4[k4]['parent'],
                "last_level":data_child4[k4]['_is_last_level'],
                "n_id":with_link,
                "version":data_child4[k4]['version'],
                "performance":data_child4[k4]['performance'],
                "density":data_child4[k4]['density'],
                "energy":data_child4[k4]['energy'],
                "emotional_coloring":data_child4[k4]['emotional_coloring'],
                "description":data_child4[k4]['description'],
                "doc1":data_child4[k4]['doc1'],
                "doc2":data_child4[k4]['doc2'],
                "doc3":data_child4[k4]['doc3'],
                "doc4":data_child4[k4]['doc4'],
                "doc5":data_child4[k4]['doc5'],
                "doc6":data_child4[k4]['doc6'],
                "doc7":data_child4[k4]['doc7'],
                "doc8":data_child4[k4]['doc8'],
                "doc9":data_child4[k4]['doc9'],
                "doc10":data_child4[k4]['doc10'],
                "doc11":data_child4[k4]['doc11'],
                "doc12":data_child4[k4]['doc12'],
                "doc13":data_child4[k4]['doc13'],
                "doc14":data_child4[k4]['doc14'],
                "doc15":data_child4[k4]['doc15'],
                "x_pos":data_child4[k4]['x_pos'],
                "y_pos":data_child4[k4]['y_pos'],
                "date_completion":data_child4[k4]['date_completion'],
                "spent_time":data_child4[k4]['spent_time'],
                "created_by":created_by,
                "_is_creator":data_child4[k4]['_is_creator']     
                            });   
                    
                        node_id++;
                        node_link[k4]=data_child4[k4]['id'];
                        node_link_p[k4]=data_child4[k4]['parent'];
                        node_link_w[k4]=node_id-1;  
                                }
                            //-------------------
                            }
                        //--------------------------
                        
                        }
                    
                    }
                //---------------------------------------------------------------------------
                
           } //end for level 1
              with_link=with_link+kk+kk1+1+kk2;
              kk=0;
              kk1=0;
              kk2=0;
                   
        } //end for main level
        
        for (var i = 0; i < node_link.length; i++) {
            
            if (parseInt(node_link_p[i])>0) {
                
                for (var ii = 0; ii < node_link.length; ii++) {
                    if (parseInt(node_link[ii])==parseInt(node_link_p[i]))
                        {
                        var n_source=node_link_w[ii];
                        var n_target=node_link_w[i];  
                        links.push({"source": n_source, "target": n_target,  "bond": 1,"id_node":node_link[ii]}); 
                        var kl=1;                         
                                 
                        }
                    }
                
               //links.push({"source": with_link+kk, "target": with_link+kk+kk1,  "bond": 1}); 
            }
            
            }
        var tt_n=node_link;
                
        //links.push({"source": 0, "target": 1,  "bond": 1});
        //links.push({"source": 0, "target": 2,  "bond": 1});
        //links.push({"source": 0, "target": 3,  "bond": 1});
        
        
        var force = d3.layout.force()
    .nodes(nodes)
    //.gravity(0.1)
    .distance(180)
    .size([w, h])
    //.theta(1)
    .charge(-1000)
    //.friction(0.5)
    //.linkDistance(function(d) { return radius(d.source.size) + radius(d.target.size) + 40; });
    .linkDistance(90);
    
    function tick(d) {
    
    
    //d.fixed = true;
     
    
    node.attr("transform", function(d) {
                
        var new_x=d.x;
        var new_y=d.y;
        
        if (d.x_pos!=0) {
            new_x=d.x_pos;
        }
        if (d.y_pos!=0) {
            new_y=d.y_pos;
        }
        
        
        var new_pos="translate(" + new_x + "," + new_y + ")";
        //if (d.id_node==67) {new_pos="translate(" + 380 + "," + 480 + ")";}
        
        //if (d.id_node==266) {new_pos="translate(" + 780 + "," + 480 + ")";}
        
        
        return new_pos;
        
        });
    
    link.selectAll("line")
        .attr("x1", function(d) {
            var new_link=d.source.x;
            //if (d.id_node==67) {var new_link=380;}
            
            
            return new_link; 
            })
        .attr("y1", function(d) { 
            var new_link=d.source.y;
            //if (d.id_node==67) {new_link=480;}
            //if (d.id_node==266) {var new_link=780;}
                            
            return new_link; 
            })
        .attr("x2", function(d) { 
            
                    var new_link=d.target.x;
               
            return new_link; 
            })
        .attr("y2", function(d) { 
           
                    var new_link=d.target.y;
             
            return new_link; 
            });
        
    
    
  }
    
    
    force
      .nodes(nodes)
      .links(links)
      .size([w, h])
      .on("tick", tick)
      .start();
      
      var link = svg.selectAll(".link")
      .data(links)
    .enter().append("g")
      .attr("class", "link");

  link.append("line")
      .style("stroke-width", function(d) { return (d.bond * 2 - 1) * 2 + "px"; });

  link.filter(function(d) { return d.bond > 1; }).append("line")
      .attr("class", "separator");
      
      var node = svg.selectAll(".node")
      .data(nodes)
    .enter().append("g")
      .attr("class", function(d) { return "node n_id"+d.id_node })
      .attr("data-id", function(d) { return d.id_node })
      .attr("level_node", function(d) { return d.level_node })
      .attr("parent_node", function(d) { return d.parent_node })
      .attr("last_level", function(d) { return d.last_level })
      .attr("version", function(d) { return d.version })
      .attr("performance", function(d) { return d.performance })
      .attr("description", function(d) { return d.description })
      .attr("doc1", function(d) { return d.doc1 })
      .attr("doc2", function(d) { return d.doc2 })
      .attr("doc3", function(d) { return d.doc3 })
      .attr("doc4", function(d) { return d.doc4 })
      .attr("doc5", function(d) { return d.doc5 })
      .attr("doc6", function(d) { return d.doc6 })
      .attr("doc7", function(d) { return d.doc7 })
      .attr("doc8", function(d) { return d.doc8 })
      .attr("doc9", function(d) { return d.doc9 })
      .attr("doc10", function(d) { return d.doc10 })
      .attr("doc11", function(d) { return d.doc11 })
      .attr("doc12", function(d) { return d.doc12 })
      .attr("doc13", function(d) { return d.doc13 })
      .attr("doc14", function(d) { return d.doc14 })
      .attr("doc15", function(d) { return d.doc15 })
      .attr("x_pos", function(d) { return d.x_pos })
      .attr("y_pos", function(d) { return d.y_pos })
      .attr("density", function(d) { return d.density })
      .attr("energy", function(d) { return d.energy })
      .attr("emotional_coloring", function(d) { return d.emotional_coloring })
      .attr("node-id", function(d,i) { return i })
      .attr("n_id", function(d) { return d.n_id })
      .attr("dx", function(d) { return d.x; })
     .attr("dy", function(d) { return d.y; })
     .attr("date_completion", function(d) { return d.date_completion; })
     .attr("spent_time", function(d) { return d.spent_time; })
     .attr("created_by", function(d) { return d.created_by; })
     .attr("_is_creator", function(d) { return d._is_creator; })     
      .call(force.drag)
      .on("mousedown", function(d) {
     d.fixed = true;
     d3.select(this).classed("sticky", true);
   });
   
   
   
    

   node.append("circle")
    .attr('class',function(d){
        
            return 'ifselect';
        
    })
      .attr("r", 33)
      .style("fill", "#000")
      .style("stroke-width", "5px")
      .style("stroke", "#fff");

var fill = d3.scale.linear()
    .domain([0, 9])
    .range(["brown", "steelblue"]);
    
    node.append("circle")
    .attr('class',function(d){
        
            return 'main_circle blue1';
        
    })
      .attr("r", function(d) { return radius(d.size)+3; })
      .style("fill", fill)
      .style("stroke", fill);
      
      
      node.append("image")
//    .attr('class',function(d) {
//        if (d.id_node==29) {
  //      return 'main_image_active';       
    //    } else {
      //  return 'main_image_noactive';    
//        }
  //  })
    .attr("xlink:href", "http://cytellect.net/tmp/node.png")
    .attr("width", "80px")
    .attr("height", "80px")
    .attr("y", "-40px")
      .attr("x", "-40px")
      .on("click", function(d) {
        var yy=this;
        node_click(d,yy);
        });
        
        
  node.append("image") //treygolnic
    .attr('class',function(d){
        
            return 'main_circle small_active';
        
    })
    .attr("xlink:href", "http://cytellect.net/tmp/node_tre.png")
    .attr("width", "32px")
    .attr("height", "29px")
    .attr("y", "-48px")
      .attr("x", "30px")
      .on("click", function(d) {
        
        kk=$(this).parent().attr('class').split(' ');
        
        var new_val=$('.node.get_select').find('text').eq(1).text();
                
        var n_desc=$('.node.get_select').attr("description");
        var n_user=$('.node.get_select').attr("created_by");
        
        var n_data=$('.node.get_select').attr("date_completion").split('-');
        
        var val = n_data[2]+'.'+n_data[1]+'.'+n_data[0];
            
        $('#myModalnew_edit .sec_slide_title .my_title_right .end_time').val(val);
        
        var if_owner=$('.node.get_select').attr("_is_creator");
        
        if (if_owner=='true') {
            $('#myModalnew_edit').removeClass('if_owner');
            $('#myModalnew_edit input').removeAttr('disabled');
            $('#myModalnew_edit textarea').removeAttr('disabled');
            $( "#slider" ).slider({ disabled: false });
            $('#myModalnew_edit .new_butt .b_right').show();
            
        } else {
            $('#myModalnew_edit').addClass('if_owner');            
            $('#myModalnew_edit input').attr('disabled','disabled');
            $('#myModalnew_edit textarea').attr('disabled','disabled');
            $( "#slider" ).slider({ disabled: true });
            
            $('#myModalnew_edit .new_butt .b_right').hide();
            
        }
        
        $('.block_attach .files_attach').text('');
        
         for(var ci = 1; ci <= 15; ci++){
        var n_doc=$('.node.get_select').attr("doc"+ci);
        if (n_doc) {
            
        $('.block_attach .files_attach').append('<div class="attach">'+n_doc+'<span class="remove_att"></span></div>');    
        }    
            }
        
        
        $('.input_center .cloud_user_name').val(n_user);
        
    $('input.cloud_name').val(new_val);
    $('#myModalnew_edit textarea').val(n_desc);
    
    var n_ener=$('.node.get_select').attr("energy");
    $( "#slider" ).slider({ value: n_ener });
    
    var n_spent_time=$('.node.get_select').attr("spent_time");
    $( "#slider1" ).slider({ value: n_spent_time });
       
       set_modal();
       
       var t=$('.node.get_select').attr('data-id');
    
    $('.node_event').text('');
    
    $.post('infostreams/GetEvents', {"infostream_id":t},
      function(data){
        
      
       var n_event=data.message;
        
        for(var i in n_event){
            
            var event_title=n_event[i]['title'];
            var event_desc=n_event[i]['description'];
            var id=n_event[i]['id'];
            var count_comm=n_event[i]['_count_comments'];
            var count_notices=n_event[i]['_count_notices'];
            
            var new_event=add_events(event_title,event_desc,id,count_comm,count_notices);
                        
            $('.node_event').append(new_event);
            
            
            
                
                }
                
                if (if_owner=='true') {
                $('.modal-footer .node_event .event_manage').show();
                } else {
                    $('.modal-footer .node_event .event_manage').hide();
                }
 ////////////////////////////////////////////////////////////  view comment
 
        $('.event_comm .comm_ico').click(function(){
            
            var position = $(this).position();
            
            var p_t=position.top;
            
            var n_p_comm=(p_t-480)+34;
            
            $('.form_comments').css('top',n_p_comm);
            
            var comm_id=$(this).parent().parent().attr('ev-id');
            
            $('.all_comm_row').text('');
            
            $.post('infostreams/GetComments', {"events_id":comm_id},
      function(data){
        
        var n_comm=data.message;
        
        for(var i in n_comm){
            var comm_user=n_comm[i]['name'];
            var comm_data=n_comm[i]['created_on'];
            var comm_text=n_comm[i]['comment'];
            var comm_id=n_comm[i]['id'];
            
            var new_comm=add_new_comm(comm_id,comm_user,comm_data,comm_text);
            $('.all_comm_row').append(new_comm);     
            
            $('.form_comments_del').click(function(){
                var to_del=$(this).parent().parent().attr('comm_id');
                
                var ev_id=$(this).parent().parent().parent().parent().parent().attr('ev-id');
                
                $('.node_event_item').each(function(){
                if ($(this).attr('ev-id')==ev_id) {
                    var c_v=parseInt($(this).find('.comm_count').text())-1;
                    $(this).find('.comm_count').text(c_v);
                }
                
                });
                
                $.post('infostreams/DeleteComment', {"id":to_del},
      function(data){
        }
        , "json");
        $(this).parent().parent().remove(); 
        
            });
            }
            
       
        
        }
        , "json");
            $('.form_comments').attr('ev-id',comm_id);
            $('.form_comments').show();
        });
 
 
 ////////////////////////////////////////////////////////////   view comment end
                
 
 
 ////////////////////////////////////////////////////        event del    
    
        $('.event_manage_del').click(function(){
            
            var to_del=$(this).parent().parent().attr('ev-id');
            
            if (to_del!='new') {
                
                $.post('infostreams/DeleteEvent', {"id":to_del},
      function(data){
        }
        , "json");
        
            }
            
           $(this).parent().parent().remove(); 
        });
 ////////////////////////////////////////////////////        event del end       
        }
        , "json");
         
        $('#myModalnew_edit').modal('show');
        //$('#myModalnew_edit').centerInClient();
        
   
    
        }); //tre click end function
      
  node.append("circle")
    .attr('class',function(d){
        
            return 'main_circle small_active';
        
    })
      .attr("r", 10)
      .attr("cy", "-3em")
      .attr("cx", "2.4em")
      .style("fill", "#fff")
      .on("click",function(d) {
        
        kk=$(this).parent().attr('class').split(' ');
        
        var new_val=$('.node.get_select').find('text').eq(1).text();
    $('input.cloud_name').val(new_val);
        
        $('#myModalnew_edit').modal('show');
        $('#myModalnew_edit').centerInClient();
      });
      
   

    function rightRoundedRect(x, y, width, height, radius) {
  return "M" + x + "," + y
       + "h" + (width - radius)
       + "a" + radius + "," + radius + " 0 0 1 " + radius + "," + radius
       + "v" + (height - 2 * radius)
       + "a" + radius + "," + radius + " 0 0 1 " + -radius + "," + radius
       + "h" + (radius - width)
       + "z";
}


function node_click(d,yy)
{
    
    
    kk=$(yy).parent().attr('class').split(' ');
        
        var tt=d3.select('.'+kk[1]).attr('class').split(' ');
      
           
      
  if ($('.testmain_edit .btn i').hasClass('ico_white')) {
        
        if ((tt[2]=='get_select')||(tt[1]=='get_select')||(tt[3]=='get_select'))
        {
        d3.select('.'+kk[1]).classed("get_select", false);
        $('.sel_val').val('0');    
        d3.selectAll('.small_active').classed("small_select", false);
        d3.selectAll('.info_ico').classed("ico_active", false);
        
        } else {
        d3.selectAll(".node").classed("get_select", false);
        d3.select('.'+kk[1]).classed("get_select", true);
        $('.nested_val').val("false");
        
        $('.sel_val').val(d3.select('.'+kk[1]).attr('data-id'));
        d3.selectAll('.small_active').classed("small_select", false);
        d3.selectAll('.info_ico').classed("ico_active", false);
        
        d3.select('.'+kk[1]).select('.info_ico').classed("ico_active", true);
        d3.select('.'+kk[1]).select('.small_active').classed("small_select", true);
        
        }
        
        
    } else {
        
        if ((tt[2]=='get_select')||(tt[1]=='get_select')||(tt[3]=='get_select'))
        {
        d3.select('.'+kk[1]).classed("get_select", false);
        
        
        
        d3.selectAll('.small_active').classed("small_select", false);
        d3.selectAll('.info_ico').classed("ico_active", false);
        
        var c_id=d3.select('.'+kk[1]).attr('data-id');
        var p_id=d3.select('.'+kk[1]).attr('parent_node');
        var l_n=d3.select('.'+kk[1]).attr('last_level');
                
        $('.sel_val').val(c_id);    
        $('.nested_val').val('true');
        
        var node_title=d3.select('.'+kk[1]).select('text').text();
        $('.testmain_back.no_active').attr('data-id',p_id);
               
        var c_lev=levels.length;
        levels[c_lev]=parseInt(c_id);
        lev_label[c_lev]=node_title;
        
        getDataInfoStreams(c_id);
        
        } else {
        d3.selectAll(".node").classed("get_select", false);
        d3.select('.'+kk[1]).classed("get_select", true);
        $('.nested_val').val("false");
        
        $('.sel_val').val(d3.select('.'+kk[1]).attr('data-id'));
        d3.selectAll('.small_active').classed("small_select", false);
        d3.selectAll('.info_ico').classed("ico_active", false);
        
        d3.select('.'+kk[1]).select('.info_ico').classed("ico_active", true);
        d3.select('.'+kk[1]).select('.small_active').classed("small_select", true);
        
        }
        
        
        
                
        $('.breadcumps').html('');
        var new_bread='';
        
        for(ci = 1; ci <= c_lev; ci++){
            new_bread=new_bread+' -> '+lev_label[ci];
            }
            
        //$('.breadcumps').html(new_bread);
        
        
    }  
}
  

    node.append("circle")
    .attr('class',function(d){
      
            return 'main_circle_none';
        
    })
      .attr("r", 8)
      .attr("cy", "-2em")
      .attr("cx", "1.2em")
      .style("fill", "red")
      .on("click", function(d) {
        kk=$(this).parent().attr('class').split(' ');
        
        var tt=d3.select('.'+kk[1]).attr('class').split(' ');
        var c_id=d3.select('.'+kk[1]).attr('data-id');
        
        var node_title=d3.select('.'+kk[1]).select('text').text();
        
        var c_lev=levels.length;
        levels[c_lev]=parseInt(c_id);
        lev_label[c_lev]=node_title;
        $('.sel_val').val(d3.select('.'+kk[1]).attr('data-id'));
        $('.nested_val').val("true");
        getDataInfoStreams(c_id);
        })

  node.append("path")
  .attr('class',function(d){
        
            return 'main_image_active';
        
    })
  .attr("d", d3.svg.arc()
    .innerRadius(function(d) {
        val_text=12;
        return val_text;
        })
    .outerRadius(function(d) { return 25; })
    .startAngle(function(d) {return 0;})
    .endAngle(function(d) {
        val_text=(d.energy*6.3)/100;
        
        return val_text;
        }))
    .attr("fill", function(d) {
       if ((d.energy>=0)&&(d.energy<=25)) {return "#9cabae";}
       if ((d.energy>=26)&&(d.energy<=50)) {return "#7aa1a9";}
       if ((d.energy>=51)&&(d.energy<=75)) {return "#73c8d3";}
       if ((d.energy>=76)&&(d.energy<=100)) {return "#3bd0e2";}
            
            
    })
    .on("click", function(d) {
    //in edit mode
    
    var yy=this;
        node_click(d,yy);
    
     
   });
  
  node.append("circle")
    .attr('class',function(d){
        
            return 'ifdata';
        
    })
      .attr("r", 8)
      .style("stroke", "#fff")
      .on("click", function(d) {
    //in edit mode
    
    var yy=this;
        node_click(d,yy);
    
     
   });
  
  node.append("text")
  .attr('class',function(d) {
        return 'main_image_active percent_node';       
    })
      .attr("dy", function(d){
        val_text="2.2em";
        
        return val_text;
      })
      .attr("dx", "-0.8em")
      .attr("text-anchor", "left")
      .attr("fill", "#fff")
      .text(function(d) {
        val_text=d.energy+'%';
        
        return val_text;
      });
      
    //  node.append("rect")
     // .attr("width", 30)
    //.attr("height", 13)
    //.attr("x", 0)
    //.attr("y", -6)
    //.style("fill", "#000");

  node.append("text")
      .attr("dy", "3em")
      .attr("dx", function(d) {
        if (d.atom) {
       var ll=d.atom.length;
       var new_ll=ll*3.5;
       return "-"+new_ll+"px";
       }  
      })
      .attr("text-anchor", "center")
      .text(function(d) { return d.atom; });
      
       
  
        $('g.node').each(function(){
            var ifsel=$(this).attr('last_level');
            if (ifsel=="false") {
                d3.select(this).select('.ifdata').classed("ifdata_act", true);
            } else {
                d3.select(this).select('.ifdata').classed("ifdata_act", false);
                
            }
        });
        
        
        
        } else {
            var url = "http://cytellect.net";    
            $(location).attr('href',url);
        }
        ajaxLoadingOff(); 
        ////////////////////////////////////////////////////////////////////////// end get tree
      }
           
    , "json");
      
};


 
////////////////////////////////////////////////////////////////////////////////////////
//functions called during ajax request to block user actions while data is being loaded:
function ajaxLoadingOn(){
		var remove;
        $('body').addClass('ajaxLoading');
        $('.container_ajax_loading').append('<div id="loading-page" class="loading"><div id="holder"></div><div id="loading-page-inner"></div></div>');
            remove = spinner("holder", 15, 40, 14, 6, "#fff");
        };

	
function ajaxLoadingOff(){
		$('body').removeClass('ajaxLoading');
        $('.container_ajax_loading').html('');  
	};
	
function isAjaxLoading(){
		if($('body').hasClass('ajaxLoading')) {
			return true;
		} else {
			return false;
		}
	};
////////////////////////////////////////////////////////////////////////////////////////
         


////////////////////////////////////////////////////////////////////////////////////////
// preloader
function get_number_f(kk) {
    var ll=kk+'';
    var ll2=ll[0];
    var ll1=ll.length;
    var new_v=ll;
    if (ll1==4) {
        new_v=ll[0]+' '+ll[1]+ll[2]+ll[3];
    }
    if (ll1==5) {
        new_v=ll[0]+ll[1]+' '+ll[2]+ll[3]+ll[4];
    }
    if (ll1==6) {
        new_v=ll[0]+ll[1]+ll[2]+' '+ll[3]+ll[4]+ll[5];
    }
    if (ll1==7) {
        new_v=ll[0]+' '+ll[1]+ll[2]+ll[3]+' '+ll[4]+ll[5]+ll[6];
    }
    if (ll1==8) {
        new_v=ll[0]+ll[1]+' '+ll[2]+ll[3]+ll[4]+' '+ll[5]+ll[6]+ll[7];
    }
    if (ll1==9) {
        new_v=ll[0]+ll[1]+ll[2]+' '+ll[3]+ll[4]+ll[5]+' '+ll[6]+ll[7]+ll[8];
    }
    //ll.formatNumber({format:"# ###", locale:"fr"});

    return new_v;
    
}

function spinner(holderid, R1, R2, count, stroke_width, colour) {
    var sectorsCount = count || 12,
        color = colour || "#fff",
        width = stroke_width || 15,
        r1 = Math.min(R1, R2) || 35,
        r2 = Math.max(R1, R2) || 60,
        cx = r2 + width,
        cy = r2 + width,
        r = Raphael(holderid, r2 * 2 + width * 2, r2 * 2 + width * 2),
        
        sectors = [],
        opacity = [],
        beta = 2 * Math.PI / sectorsCount,

        pathParams = {stroke: color, "stroke-width": width, "stroke-linecap": "round"};
        Raphael.getColor.reset();
    for (var i = 0; i < sectorsCount; i++) {
        var alpha = beta * i - Math.PI / 2,
            cos = Math.cos(alpha),
            sin = Math.sin(alpha);
        opacity[i] = 1 / sectorsCount * i;
        sectors[i] = r.path([["M", cx + r1 * cos, cy + r1 * sin], ["L", cx + r2 * cos, cy + r2 * sin]]).attr(pathParams);
        if (color == "rainbow") {
            sectors[i].attr("stroke", Raphael.getColor());
        }
    }
    var tick;
    (function ticker() {
        opacity.unshift(opacity.pop());
        for (var i = 0; i < sectorsCount; i++) {
            sectors[i].attr("opacity", opacity[i]);
        }
        r.safari();
        tick = setTimeout(ticker, 1000 / sectorsCount);
    })();
    return function () {
        clearTimeout(tick);
        r.remove();
    };
}

function set_disable()
{
    
}

var bDatan=[];
//////////////////////////////////////////////////////////////////////// add comment
function add_new_comm(com_id,comm_user,comm_data,comm_text)
{
  var i='<div class="form_comments_1" comm_id="'+com_id+'">';
                    i+='<div class="form_comments_ico"></div>';
                    i+='<div class="form_comments_all">';
                        i+='<div class="form_comments_top">';
                            i+='<div class="form_comments_user">';
                            i+=comm_user;
                            i+='</div>';
                            i+='<div class="form_comments_data">';
                            i+=comm_data;
                            i+='</div>';
                        i+='</div>';
                        i+='<div class="form_comments_text">';
                        i+=comm_text;
                        i+='</div>';
                    i+='</div>';
                    
                    if ($('#myModalnew_edit').hasClass('if_owner')) {
                        
                    } else {
                    i+='<div class="form_comments_butt">';
                    i+='<div class="form_comments_del">';
                    i+='×';
                    i+='</div>';
                    i+='<div class="form_comments_edit">E';
                    i+='</div>';
                    i+='</div>';
                    }
                i+='</div>';
                
                return i;
}

/////////////////////////////////////////////////////////////////////    add comment end

/////////////////////////////////////////////////////////////////////////   add_event
function add_events(title,desc,id,count_comm,count_notices)
{
  var i='<div class="node_event_item" ev-id="'+id+'">';
            i+='<div class="event_manage">';
            i+='<div class="event_manage_del">×';
            i+='</div>';
            i+='<div class="event_manage_edit">E';
            i+='</div>';
            i+='</div>';
            i+='<div class="event_title">';
            i+=title;
            i+='</div>';
            i+='<div class="event_desc">';
            i+=desc;
            i+='</div>';
            
            i+='<div class="event_comm">';
                i+='<div class="comm_ico">';
                i+='</div>';
                i+='<div class="comm_count">';
                i+=count_comm;
                i+='</div>';
                i+='<div class="comm_text">комментариев';
                i+='</div>';
                i+='<div class="comm_new">(+';
                i+=count_notices;
                i+=')</div>';
            i+='</div>';
            
            i+='</div>'; 
            
            return i; 
}

/////////////////////////////////////////////////////////////////////////   add_event_end

$(document).ready(function()
{
        
        
    d3.select("body").style("background-color", "black");
    $('.nested_val').val("false");
    levels[0]=0;
    
        var c_id='';
        if (document.getElementById('target_matrix')==null) {
      getDataInfoStreams(c_id);
      }
      
      
  // setInterval('getDataInfoStreams()', 30000);
  
  if (document.getElementById('main_info')!=null) {
    $('.container').addClass('main_info_page');
    $('.container div.row').eq(1).addClass('main_info_row');
  }

    $('.testmain_edit a').click(function(){
        if ($('.testmain_add').hasClass('view')) {
        $('.testmain_add').removeClass('view');
        $('.testmain_remove').removeClass('view');
        $('.testmain_edit_node').removeClass('view');
        $('.testmain_del_from_node').removeClass('view');
        $('.testmain_add_to_node').removeClass('view');
        
        d3.selectAll(".node").classed("get_select", false);
        d3.selectAll('.small_active').classed("small_select", false);
        $('.sel_val').val('0');
        $('.testmain_edit a .icon-edit').attr('class','icon-edit');
        
        set_disable();
        
    } else {
        $('.testmain_add').addClass('view');
        $('.testmain_remove').addClass('view');
        $('.testmain_edit_node').addClass('view');
        $('.testmain_del_from_node').addClass('view');
        $('.testmain_add_to_node').addClass('view');
        $('.testmain_edit a .icon-edit').attr('class','icon-edit ico_white');
    }
        
       return false; 
    });
    
    $('.testmain_back.no_active a').click(function(){
                
        levels.pop();
        lev_label.pop();
        var lev_c=levels.length;
        var p_id=levels[lev_c-1];
        $('.nested_val').val("false");
        
        $('.breadcumps').html('');
        var new_bread='';
        
        for(ci = 1; ci <= lev_c-1; ci++){
            new_bread=new_bread+' -> '+lev_label[ci];
            }
            
        $('.breadcumps').html(new_bread);
        
        getDataInfoStreams(p_id);
        
       return false; 
    });
    
       
    $('.testmain_edit').click(function(){
        return false;
    });
    
    $('.testmain_remove').click(function(){

    });
  
  $('.testmain_edit_node').click(function(){
    
    $('#myModalnew .modal-footer .btn').eq(1).removeClass('add_new');
    $('#myModalnew .modal-footer .btn').eq(1).addClass('edit_new');
    
    set_modal();
    
    var new_val=$('.node.get_select').find('text').eq(1).text();
    $('input.cloud_name').val(new_val);
    
    });
  
  $('.testmain_add').click(function(){
    $('#myModalnew .modal-footer .btn').eq(1).removeClass('edit_new');
    $('#myModalnew .modal-footer .btn').eq(1).addClass('add_new');
    
    $('#myModalnew .modal-body .cloud_name_add').val('');
    
    });
  
  $('#myModalnew .modal-footer .btn').eq(1).click(function(){
    if ($(this).hasClass('add_new')) {
        var cloud_name=$('input.cloud_name_add').val();
        if (cloud_name!="") {
        $('#myModalnew').modal('hide');
      ajaxLoadingOn();
      
      var c_id=0;

      
           
      var t=$('.sel_val').val();
      if (parseInt(t)==0) {
        c_id=0;
        } 
        else {
        c_id=t;
      }
      
      var nested_level=$('.nested_val').val();
      
      $.post('infostreams/add', {"parent":c_id,"nested_level":nested_level,"title":cloud_name},
      function(data){
        }
        , "json");
        
      $.wait(1000).then(function(){
        
        var c_lev=levels.length;
        var cur_level=levels[c_lev-1];
        $('.sel_val').val('0');
        getDataInfoStreams(cur_level);
         
    
        ajaxLoadingOff();
        });
        }
    }
    
        
  });  
  
  ///////////////////////////////////////////    edit node function
  
  $('#myModalnew_edit .new_butt .btn').eq(0).click(function(){
    
    var cloud_name=$('input.cloud_name').val();
        $('.node.get_select').find('text').eq(1).text(cloud_name);
        $('#myModalnew_edit').modal('hide');
        
        var n_ener=$('#slider').slider('value');
        
        $('.node.get_select').attr("description",$('.node_desc').val());
        
        
        var ty=$('#myModalnew_edit .modal-body .my_title_right .end_time').val().split('.');
        var date_completion=ty[2]+'-'+ty[1]+'-'+ty[0];
        
        var node_version=$('.node.get_select').attr('version');
        var node_name=cloud_name;
        var node_id=$('.node.get_select').attr('data-id');
        var performance=$('.node.get_select').attr('performance');
        var description=$('.node.get_select').attr('description');
        
        var doc1=$('.node.get_select').attr('doc1');
        var doc2=$('.node.get_select').attr('doc2');
        var doc3=$('.node.get_select').attr('doc3');
        var doc4=$('.node.get_select').attr('doc4');
        var doc5=$('.node.get_select').attr('doc5');
        var doc6=$('.node.get_select').attr('doc6');
        var doc7=$('.node.get_select').attr('doc7');
        var doc8=$('.node.get_select').attr('doc8');
        var doc9=$('.node.get_select').attr('doc9');
        var doc10=$('.node.get_select').attr('doc10');
        var doc11=$('.node.get_select').attr('doc11');
        var doc12=$('.node.get_select').attr('doc12');
        var doc13=$('.node.get_select').attr('doc13');
        var doc14=$('.node.get_select').attr('doc14');
        var doc15=$('.node.get_select').attr('doc15');
        var x_pos=$('.node.get_select').attr('x_pos');
        var y_pos=$('.node.get_select').attr('y_pos');
        var density=$('.node.get_select').attr('density');
        var energy=n_ener;
        var emotional_coloring=$('.node.get_select').attr('emotional_coloring');
        
        x_pos=0;
        y_pos=0;
                
        ajaxLoadingOn();
        
        $.post('infostreams/edit', {
            "id":node_id,
            "title":node_name,
            "performance":performance,
            "description":description,
            "version":node_version,
            "doc1":doc1,
            "doc2":doc2,
            "doc3":doc3,
            "doc4":doc4,
            "doc5":doc5,
            "doc6":doc6,
            "doc7":doc7,
            "doc8":doc8,
            "doc9":doc9,
            "doc10":doc10,
            "doc11":doc11,
            "doc12":doc12,
            "doc13":doc13,
            "doc14":doc14,
            "doc15":doc15,
            "x_pos":x_pos,
            "y_pos":y_pos,
            "density":density,
            "energy":energy,
            "emotional_coloring":emotional_coloring,
            "date_completion":date_completion
            },
      function(data){
        }
        , "json");
        
        $.wait(1000).then(function(){
        
        var c_lev=levels.length;
        var cur_level=levels[c_lev-1];
        $('.sel_val').val('0');
        getDataInfoStreams(cur_level);
        
        ajaxLoadingOff();
        });
  });
  //////////////////////////////////////////
  
  $('#myModalnew_del .btn.btn-primary-del').click(function(){ //del node
    
    $('#myModalnew_del').modal('hide');
      ajaxLoadingOn();
      
    var t=$('.node.get_select').attr('data-id');
    
    $.post('infostreams/delete', {"id":t},
      function(data){
        }
        , "json");
        
    $.wait(1000).then(function(){
        
        var c_lev=levels.length;
        var cur_level=levels[c_lev-1];
        $('.sel_val').val('0');
        getDataInfoStreams(cur_level);
        
        ajaxLoadingOff();
        });
  });
    

//svg.selectAll("rect")
//    .data(d3.range(x * y))
//  .enter().append("rect")
//    .attr("transform", translate)
//    .attr("width", z)
//    .attr("height", z)
//    .style("fill", function(d) { return d3.hsl(d % x / x * 360, 1, Math.floor(d / x) / y); })
//    .on("mouseover", mouseover);
//
//function translate(d) {
//  return "translate(" + (d % x) * z + "," + Math.floor(d / x) * z + ")";
//}
//
//function mouseover(d) {
//  this.parentNode.appendChild(this);
//
//  d3.select(this)
//      .style("pointer-events", "none")
//    .transition()
//      .duration(1500)
//      .attr("transform", "translate(480,480)scale(23)rotate(180)")
//    .transition()
//      .delay(1500)
//      .attr("transform", "translate(240,240)scale(0)")
//      .style("fill-opacity", 0)
//      .remove();
//}
    
    if (document.getElementById('testmain_center')!=null) {
    $('.main_info_head').hide();
    $('.navbar').hide();
    $('hr').hide();
    $('.new_f').hide();
    $('body').css('padding-top','0px');
  }
    
    $( "#slider" ).slider({
   slide: function(event, ui) {
    $( "#slider a").text($(this).slider('value')+'%');
    $('.node.get_select').attr('energy',$(this).slider('value'));
   },
   change: function(event, ui) {
    $( "#slider a").text($(this).slider('value')+'%');
    $('.node.get_select').attr('energy',$(this).slider('value'));
   },
   range:"min"
});

$( "#slider1" ).slider({
   slide: function(event, ui) {
    $( "#slider1 a").text($(this).slider('value')+'%');
    $('.node.get_select').attr('energy',$(this).slider('value'));
   },
   change: function(event, ui) {
    $( "#slider1 a").text($(this).slider('value')+'%');
    $('.node.get_select').attr('energy',$(this).slider('value'));
   },
   range:"min",
   disabled: true
});

$( "#slider a").text('0%');
$( "#slider1 a").text('0%');


$('.check_opt').mouseover(function(){
    $(this).attr('data-content','РЈСЃС‚Р°РЅРѕРІРёС‚СЊ/РЎРЅСЏС‚СЊ');
    $(this).attr('data-title','РЎРёРіРЅР°Р»');
    $(this).attr('data-placement','right');
    $(this).popover();
    $(this).popover('show');
});

$('.check_opt').mouseout(function(){
    
    $(this).popover('hide');
});

$('.alert_opt').mouseover(function(){
    $(this).attr('data-content','РЈСЃС‚Р°РЅРѕРІРёС‚СЊ РґР°С‚Сѓ Рё РІСЂРµРјСЏ');
    $(this).attr('data-title','РќР°РїРѕРјРёРЅР°РЅРёРµ');
    $(this).attr('data-placement','left');
    $(this).popover();
    $(this).popover('show');
});

$('.alert_opt').mouseout(function(){
    
    $(this).popover('hide');
});
  
  
$('.check_opt').click(function(){
    
    if ($('.check_opt i').hasClass('ico-white')) {
        $('.check_opt i').removeClass('ico-white');
    } else {
        $('.check_opt i').addClass('ico-white');
    }
});  

$('.close_comm').click(function(){
    $('.form_comments').hide();
});



    //set node desc
    
    $('.node_desc').change(function(){
        
    $('.node.get_select').attr("description",$(this).val());    
    });
    
    
    $('.add_event').click(function(){
        if ($(this).hasClass('event_ready')) {
        $(this).removeClass('event_ready');
            $('.add_event_form').hide();
            var event_title=$('.event_name').val();
            var event_desc=$('.add_event_form .input_center .event_desc').val();
            
            var id='new';
            var new_event=add_events(event_title,event_desc,id);
            
            if (event_title.length>0) {
            $('.node_event').append(new_event);
            
            ajaxLoadingOn();
      
    var t=$('.node.get_select').attr('data-id');
    
    $.post('infostreams/AddEvent', {"infostream_id":t,"title":event_title,"description":event_desc},
      function(data){
        
        var t_id=data.message;
        var n_id=t_id['id'];
        
        $('.node_event .node_event_item').last().attr('ev-id',n_id);
        
        $('.event_manage_del').click(function(){
            
            var to_del=$(this).parent().parent().attr('ev-id');
            
            if (to_del!='new') {
                
                $.post('infostreams/DeleteEvent', {"id":to_del},
      function(data){
        }
        , "json");
        
            }
            
           $(this).parent().parent().remove(); 
        });
        
        ajaxLoadingOff();
        }
        , "json");
        
        
        
            }
            
        } else {
            $('.event_name').val('');
            $('.event_desc').val('');
            $('.add_event_form').show();
        $(this).addClass('event_ready');
        }
        
    });


$('#myModalnew_edit .close').click(function(){
 var n_ener=$('#slider').slider('value');
 $('.form_comments').hide();
        
        $('.node.get_select').attr("energy",n_ener);   
})
 
 ////////////////////////////////////////////////////////////            add comment in form
$('.comm_add_butt').click(function(){
    if ($('.comm_area').hasClass('view_area_comm')) {
        $('.comm_area').removeClass('view_area_comm');
        
        if ($('.comm_area .event_desc').val().length>0) {
            
            var ev_id=$('.form_comments').attr('ev-id');
            var comm_text=$('.comm_area .event_desc').val();
            
            $('.node_event_item').each(function(){
                if ($(this).attr('ev-id')==ev_id) {
                    var c_v=parseInt($(this).find('.comm_count').text())+1;
                    $(this).find('.comm_count').text(c_v);
                }
                
                });
            
            $.post('infostreams/AddComment', {"events_id":ev_id,"comment":comm_text},
            function(data){
                
            var t_id=data.message;
        var n_id=t_id['id'];
        var comm_user=t_id['name'];
        var comm_data=t_id['created_on'];
        
                           
            var new_comm=add_new_comm(n_id,comm_user,comm_data,comm_text);
            $('.all_comm_row').append(new_comm);
            
            $('.form_comments_del').click(function(){
                var to_del=$(this).parent().parent().attr('comm_id');
                
                var ev_id=$(this).parent().parent().parent().parent().parent().attr('ev-id');
                
                $('.node_event_item').each(function(){
                if ($(this).attr('ev-id')==ev_id) {
                    var c_v=parseInt($(this).find('.comm_count').text())-1;
                    $(this).find('.comm_count').text(c_v);
                }
                
                });
                
                $.post('infostreams/DeleteComment', {"id":to_del},
      function(data){
        }
        , "json");
        $(this).parent().parent().remove(); 
        
            });
            
                        }
            , "json");
        }
        
    } else {
        $('.comm_area .event_desc').val('');
        $('.comm_area').addClass('view_area_comm');
    }
});

////////////////////////////////////////////   add comment form end

});



$(function() {
    
    var currentTime = new Date ( );
      var currentHours = currentTime.getHours ( );
      var currentMinutes = currentTime.getMinutes ( );
      var currentSeconds = currentTime.getSeconds ( );
      
      currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
      currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
      
      var currentYear=currentTime.getFullYear();
      var currentDay=currentTime.getDate();
      var currentMonth=currentTime.getMonth();
      currentMonth=currentMonth+1;
      
      currentDay = ( currentDay < 10 ? "0" : "" ) + currentDay;
      currentMonth = ( currentMonth < 10 ? "0" : "" ) + currentMonth;
      
      
      //date_start1=currentYear+'-'+currentMonth+'-'+currentDay+' '+'00:00:00';
      date_start1='2012-09-28 15:00:00';
      date_end1=currentYear+'-'+currentMonth+'-'+currentDay+' '+currentHours+':'+currentMinutes+':'+currentSeconds;
    
    //getDataInfoStreams(date_start1,date_end1);

   });

/////////////////////////////////////////////////////